package com.teemor.tim.contoller;

import com.teemor.common.bean.utils.BeanConvertor;
import com.teemor.common.bean.utils.tmpl.BaseController;
import com.teemor.common.bean.utils.tmpl.ResponseBen;
import com.teemor.tim.bean.form.cs.TransferCsForm;
import com.teemor.tim.bean.result.cs.CsUserResult;
import com.teemor.tim.bean.result.message.MessageRecordResult;
import com.teemor.tim.enums.UserType;
import com.teemor.tim.processor.CustomerServiceProcessor;
import com.teemor.tim.processor.MessageProcessor;
import com.teemor.tim.model.search.MessageRecordSearch;
import com.teemor.tim.model.user.UserStateModel;
import com.teemor.tim.processor.UserStateProcessor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/12/17 15:46
 */
@Api(tags = "客服接口")
@RequestMapping("cs")
@RestController
public class CsController extends BaseController {


    @Autowired
    private CustomerServiceProcessor customerServiceProcessor;
    @Autowired
    private MessageProcessor messageProcessor;
    @Autowired
    private UserStateProcessor userStateProcessor;

    @ApiOperation("选择客服")
    @GetMapping(value = "/select")
    public void select(@RequestParam String userId) {
        customerServiceProcessor.selectSeat(userId);
    }

    @ApiOperation("切换客服")
    @PostMapping(value = "/transfer")
    public void transfer(@RequestBody TransferCsForm form) {
        customerServiceProcessor.transferSeat(form);
    }

    @ApiOperation("查询在线客服列表")
    @GetMapping(value = "/list")
    public ResponseBen<List<CsUserResult>> list() {
        List<UserStateModel> userStateModels = userStateProcessor.getUserStates(UserType.CUSTOMER_SERVICE);
        List<CsUserResult> results = BeanConvertor.convertBeanList(userStateModels, CsUserResult.class);
        return returnSuccess(results);
     }

     @ApiOperation("查询消息列表")
     @GetMapping(value = "/messages")
     public ResponseBen<List<MessageRecordResult>> messages(@ModelAttribute MessageRecordSearch form) {
        List<MessageRecordResult> messageWrappers = messageProcessor.getMessages(form);
        return returnSuccess(messageWrappers);
     }


}
